Global Crop Production
Graphs of global crop production using FAO data
Prepare Data
myCaption <- "derekmichaelwright.github.io/dblogr/ | Data: STATCAN"
#
dd <- agData_FAO_Crops %>% filter(Area == "World")PDF - All Crops
# Prep data
myColors <- c("darkgreen", "darkred", "darkgoldenrod2")
xx <- dd %>%
mutate(Value = ifelse(Measurement %in% c("Area Harvested","Production"),
Value / 1000000, Value / 1000),
Unit = plyr::mapvalues(Unit, c("hectares", "tonnes", "kg/ha"),
c("Million Hectares", "Million Tonnes", "Tonnes/ Hectare")))
myCrops <- unique(xx$Crop)
# Plot
pdf("figures_crops_world_fao.pdf", width = 12, height = 4)
for(i in myCrops) {
xi <- xx %>% filter(Item == i)
print(ggplot(xi, aes(x = Year, y = Value, color = Measurement)) +
geom_line(size = 1.5, alpha = 0.7) +
facet_wrap(. ~ Measurement + Unit, scales = "free_y", ncol = 3) +
scale_color_manual(values = myColors) +
scale_x_continuous(breaks = seq(1960, 2020, by = 5) ) +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = i, y = NULL, x = NULL,
caption = myCaption) )
}
dev.off()1908 Vs. 1961 Vs. 2020
cropList function
# Create function to determine top crops
cropList <- function(measurement, years) {
# Prep data
xx <- agData_FAO_Crops %>%
filter(Area == "World", Measurement == measurement, Year %in% years,
Item != "Rice, paddy (rice milled equivalent)")
# Get top 15 crops from each year
topcrops <- function(x, year) {
x <- x %>% filter(Year == year) %>% arrange(desc(Value)) %>%
pull(Item) %>% unique() %>% as.character()
}
myCrops <- NULL
for(i in years) { myCrops <- c(myCrops, topcrops(xx, i)) }
unique(myCrops)
}Production
# Prep data
myCrops <- cropList(measurement = "Production", years = c(2019, 1961))[1:15]
xx <- dd %>%
filter(Year %in% c(2019, 1961),
Measurement == "Production", Item %in% myCrops) %>%
mutate(Text = ifelse(Item == "Sugar cane" & Year == 2019,
paste0("~", round(Value / 1000000), " Tonnes"), NA),
Item = factor(Item, levels = myCrops) )
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000000, fill = Item)) +
geom_col(color = "Black", alpha = 0.7) +
geom_text(aes(label = Text), y = 1180, angle = 270, hjust = 0, vjust = 0.5) +
facet_grid(Year ~ .) +
scale_fill_manual(values = agData_Colors) +
scale_y_continuous(breaks = seq(0, 1200, by = 200)) +
coord_cartesian(ylim = c(0,1150)) +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "World - Crop Production",
y = "Million Tonnes", x = NULL, caption = myCaption)
ggsave("crops_world_1_01.png", mp, width = 6, height = 4)Area Harvested

# Prep data
myCrops <- cropList(measurement = "Area Harvested", years = c(2019, 1961))[1:20]
xx <- dd %>%
filter(Year %in% c(2019, 1961),
Measurement == "Area Harvested", Item %in% myCrops) %>%
mutate(Item = factor(Item, levels = myCrops),
Item = plyr::mapvalues(Item, "Groundnuts, with shell", "Groundnuts"))
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000000, fill = Item)) +
geom_col(color = "Black", alpha = 0.7) +
facet_grid(Year ~ .) +
scale_fill_manual(values = agData_Colors) +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "World - Area Harvested",
y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_world_02.png", mp, width = 6, height = 4)